package ro.ubb.web.books;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ro.ubb.dataaccess.entities.Book;
import ro.ubb.executor.Executor;

public class GetAllBooks extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@EJB(name = "ro.ubb.executor.Executor", beanName = "ExecutorEJB")
	private Executor executor;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Writer out = response.getWriter();
		List<Book> books = executor.getAllBooks();
		out.append("Result:\n");
		if (books.isEmpty()) {
			out.append("Empty!");
		}
		for (Book book : books) {
			out.append(book.toString() + "\n");
		}
	}
}
